<template>
	<view class="search-box">
		<my-search bgcolor="green" radius="20" @click="gotoSearch"></my-search>
	</view>
	<view>
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000">
			<swiper-item v-for="(item,i) in swiperList" :key="i">
				<navigator class="swiper-item" :url="'/subpkg/goods_detail/goods_detail?goods_id=' + item.goods_id">
					<image :src="item.image_src"></image>
				</navigator>
			</swiper-item>
		</swiper>
	</view>
	<view class="nav-list">
		<image v-for="(item,i) in navList" :key="i" :src="item.image_src" @click="navClickHandler(item)"></image>
	</view>
	<view class="floor-list">
		<view class='floor-item' v-for="(item,i) in floorList" :key="i">
			<image :src="item.floor_title.image_src" class="floor-title" mode="widthFix"></image>
			<view class="product-list">
				<navigator class="sideProduct" :url="item.product_list[0].url">
					<image :src="item.product_list[0].image_src" mode="widthFix" :style="{width:item.product_list[0].image_width+'rpx'}"></image>
				</navigator>
				<view class="product">
					<navigator class="product-item" v-for="(item2,i2) in item.product_list"  :key="i2" :url="item2.url">
						<image :src="item2.image_src" mode="widthFix" :style="{width:item2.image_width+'rpx'}" v-if="i2!==0"></image>
					</navigator>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import { $http } from '@escook/request-miniprogram';
import badgeMix from '@/mixins/tabbar-badge.js'
	export default {
		mixins: [badgeMix],
		data() {
			return {
				swiperList : [],
				navList:[],
				floorList:[]
			}
		},
		onLoad() {
			this.getSwiperList()
			//this.getNavList()
			//this.getFloorList()
		},
		methods : {
			async getSwiperList(){
				const {data:res} = await uni.$http.get('/api/public/v1/home/swiperdata')
				if (res.meta.status!==200){
					uni.$showMsg()
				}
				else{
					this.swiperList = res.message
				}
			},
			async getNavList(){
				const {data:res} = await $http.get("/api/public/v1/home/catitems")
				if (res.meta.status!==200){
					uni.$showMsg()
				}
				else{
					this.navList=res.message
				}
			},
			async getFloorList(){
				const {data:res} = await $http.get("/api/public/v1/home/floordata")
				if (res.meta.status!==200){
					uni.$showMsg()
				}
				else{
					this.floorList = res.message
					this.floorList.forEach(floor=>{
						floor.product_list.forEach(prod=>{
							prod.url = '/subpkg/goods_list/goods_list?'+prod.navigator_url.split('?')[1]
						})
					})
				}
			},
			navClickHandler(item){
				if (item.name=='分类'){
					uni.switchTab({
						url:"/pages/cate/cate"
					})
				}
			},
			gotoSearch(){
				uni.navigateTo({
					url:'/subpkg/search/search'
				})
			}
		},
	}
</script>

<style lang="scss">
	swiper{
		height: 330rpx;
		.swiper-item{
			height: 100%;
			width: 100%;
		}
		image{
			height: 100%;
			width: 100%;
		}
	}
	.nav-list{
		display: flex;
		justify-content: space-around;
		height: 188rpx;
		width:100%;
		margin-top: 10rpx;
		image{
			height: 140rpx;
			width: 128rpx;
			margin: 10rpx;
		}
	}
	.floor-list{
		display: flex;
		margin: 5rpx;
		flex-direction: column;
	}
	.floor-item{
		display: flex;
		margin: 5rpx;
		flex-direction: column;
		.product-list{
			display: flex;
			padding: 10rpx;
			.product{
				padding: 5rpx;
				display: flex;
				flex-wrap: wrap;
				justify-content: space-around;
			}
		}
	}
	.search-box{
		position: sticky;
		top: 0;
		z-index:999
	}
</style>
